package c.e.a.b.e.c;

import c.e.a.b.e.c.u4.b;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.logging.Logger;

/* compiled from: com.google.android.gms:play-services-measurement-base@@18.0.0 */
public final class n4<T extends p4<T>> {
    public static final n4 d = new n4(true);
    public final t6<T, Object> a = new v6(16);
    public boolean b;
    public boolean c;

    public n4(boolean z) {
        int i = t6.g;
        h();
        h();
    }

    public static int a(p4<?> p4Var, Object obj) {
        r7 r = p4Var.r();
        int q = p4Var.q();
        if (!p4Var.f()) {
            return b(r, q, obj);
        }
        int i = 0;
        if (p4Var.g()) {
            for (Object obj2 : (List) obj2) {
                i += g(r, obj2);
            }
            return (e4.D(q) + i) + e4.L(i);
        }
        for (Object obj22 : (List) obj22) {
            i += b(r, q, obj22);
        }
        return i;
    }

    public static int b(r7 r7Var, int i, Object obj) {
        i = e4.D(i);
        if (r7Var == r7.GROUP) {
            e6 e6Var = (e6) obj;
            if (e6Var instanceof m3) {
                m3 m3Var = (m3) e6Var;
            }
            i <<= 1;
        }
        return g(r7Var, obj) + i;
    }

    public static Object d(Object obj) {
        if (obj instanceof h6) {
            return ((h6) obj).q();
        }
        if (!(obj instanceof byte[])) {
            return obj;
        }
        byte[] bArr = (byte[]) obj;
        byte[] bArr2 = new byte[bArr.length];
        System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
        return bArr2;
    }

    /* JADX WARNING: Missing block: B:5:0x0019, code skipped:
            if ((r2 instanceof c.e.a.b.e.c.f5) == false) goto L_0x0041;
     */
    /* JADX WARNING: Missing block: B:9:0x0022, code skipped:
            if ((r2 instanceof c.e.a.b.e.c.y4) == false) goto L_0x0041;
     */
    /* JADX WARNING: Missing block: B:13:0x002b, code skipped:
            if ((r2 instanceof byte[]) == false) goto L_0x0041;
     */
    /* JADX WARNING: Missing block: B:14:0x002d, code skipped:
            r1 = true;
     */
    /* JADX WARNING: Missing block: B:21:0x0041, code skipped:
            r1 = false;
     */
    /* JADX WARNING: Missing block: B:22:0x0042, code skipped:
            if (r1 == false) goto L_0x0045;
     */
    /* JADX WARNING: Missing block: B:23:0x0044, code skipped:
            return;
     */
    /* JADX WARNING: Missing block: B:25:0x004c, code skipped:
            throw new java.lang.IllegalArgumentException("Wrong object type used with protocol message reflection.");
     */
    public static void e(c.e.a.b.e.c.r7 r1, java.lang.Object r2) {
        /*
        r0 = c.e.a.b.e.c.w4.a;
        java.util.Objects.requireNonNull(r2);
        r0 = c.e.a.b.e.c.m4.a;
        r1 = r1.a;
        r1 = r1.ordinal();
        r1 = r0[r1];
        switch(r1) {
            case 1: goto L_0x003e;
            case 2: goto L_0x003b;
            case 3: goto L_0x0038;
            case 4: goto L_0x0035;
            case 5: goto L_0x0032;
            case 6: goto L_0x002f;
            case 7: goto L_0x0025;
            case 8: goto L_0x001c;
            case 9: goto L_0x0013;
            default: goto L_0x0012;
        };
    L_0x0012:
        goto L_0x0041;
    L_0x0013:
        r1 = r2 instanceof c.e.a.b.e.c.e6;
        if (r1 != 0) goto L_0x002d;
    L_0x0017:
        r1 = r2 instanceof c.e.a.b.e.c.f5;
        if (r1 == 0) goto L_0x0041;
    L_0x001b:
        goto L_0x002d;
    L_0x001c:
        r1 = r2 instanceof java.lang.Integer;
        if (r1 != 0) goto L_0x002d;
    L_0x0020:
        r1 = r2 instanceof c.e.a.b.e.c.y4;
        if (r1 == 0) goto L_0x0041;
    L_0x0024:
        goto L_0x002d;
    L_0x0025:
        r1 = r2 instanceof c.e.a.b.e.c.t3;
        if (r1 != 0) goto L_0x002d;
    L_0x0029:
        r1 = r2 instanceof byte[];
        if (r1 == 0) goto L_0x0041;
    L_0x002d:
        r1 = 1;
        goto L_0x0042;
    L_0x002f:
        r1 = r2 instanceof java.lang.String;
        goto L_0x0042;
    L_0x0032:
        r1 = r2 instanceof java.lang.Boolean;
        goto L_0x0042;
    L_0x0035:
        r1 = r2 instanceof java.lang.Double;
        goto L_0x0042;
    L_0x0038:
        r1 = r2 instanceof java.lang.Float;
        goto L_0x0042;
    L_0x003b:
        r1 = r2 instanceof java.lang.Long;
        goto L_0x0042;
    L_0x003e:
        r1 = r2 instanceof java.lang.Integer;
        goto L_0x0042;
    L_0x0041:
        r1 = 0;
    L_0x0042:
        if (r1 == 0) goto L_0x0045;
    L_0x0044:
        return;
    L_0x0045:
        r1 = new java.lang.IllegalArgumentException;
        r2 = "Wrong object type used with protocol message reflection.";
        r1.<init>(r2);
        throw r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.e.c.n4.e(c.e.a.b.e.c.r7, java.lang.Object):void");
    }

    public static <T extends p4<T>> boolean f(Entry<T, Object> entry) {
        p4 p4Var = (p4) entry.getKey();
        if (p4Var.s() == y7.MESSAGE) {
            if (p4Var.f()) {
                for (e6 f : (List) entry.getValue()) {
                    if (!f.f()) {
                        return false;
                    }
                }
            }
            Object value = entry.getValue();
            if (value instanceof e6) {
                if (!((e6) value).f()) {
                    return false;
                }
            } else if (value instanceof f5) {
                return true;
            } else {
                throw new IllegalArgumentException("Wrong object type used with protocol message reflection.");
            }
        }
        return true;
    }

    public static int g(r7 r7Var, Object obj) {
        int b;
        int L;
        Logger logger;
        e6 e6Var;
        switch (m4.b[r7Var.ordinal()]) {
            case 1:
                ((Double) obj).doubleValue();
                logger = e4.b;
                return 8;
            case 2:
                ((Float) obj).floatValue();
                logger = e4.b;
                return 4;
            case 3:
                return e4.F(((Long) obj).longValue());
            case 4:
                return e4.F(((Long) obj).longValue());
            case 5:
                return e4.H(((Integer) obj).intValue());
            case 6:
                ((Long) obj).longValue();
                logger = e4.b;
                return 8;
            case 7:
                ((Integer) obj).intValue();
                logger = e4.b;
                return 4;
            case 8:
                ((Boolean) obj).booleanValue();
                logger = e4.b;
                return 1;
            case 9:
                e6Var = (e6) obj;
                logger = e4.b;
                return e6Var.b();
            case 10:
                if (!(obj instanceof f5)) {
                    e6Var = (e6) obj;
                    logger = e4.b;
                    b = e6Var.b();
                    L = e4.L(b);
                    break;
                }
                f5 f5Var = (f5) obj;
                logger = e4.b;
                b = f5Var.a();
                L = e4.L(b);
                break;
            case 11:
                if (obj instanceof t3) {
                    return e4.p((t3) obj);
                }
                return e4.q((String) obj);
            case 12:
                if (!(obj instanceof t3)) {
                    byte[] bArr = (byte[]) obj;
                    logger = e4.b;
                    b = bArr.length;
                    L = e4.L(b);
                    break;
                }
                return e4.p((t3) obj);
            case 13:
                return e4.L(((Integer) obj).intValue());
            case 14:
                ((Integer) obj).intValue();
                logger = e4.b;
                return 4;
            case 15:
                ((Long) obj).longValue();
                logger = e4.b;
                return 8;
            case 16:
                return e4.O(((Integer) obj).intValue());
            case 17:
                return e4.K(((Long) obj).longValue());
            case 18:
                if (obj instanceof y4) {
                    return e4.H(((y4) obj).q());
                }
                return e4.H(((Integer) obj).intValue());
            default:
                throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
        }
        return L + b;
    }

    public static int k(Entry<T, Object> entry) {
        p4 p4Var = (p4) entry.getKey();
        Object value = entry.getValue();
        if (p4Var.s() != y7.MESSAGE || p4Var.f() || p4Var.g()) {
            return a(p4Var, value);
        }
        int L;
        int M;
        int a;
        int L2;
        if (value instanceof f5) {
            f5 f5Var = (f5) value;
            L = e4.L(8) << 1;
            M = e4.M(2, ((p4) entry.getKey()).q()) + L;
            L = e4.L(24);
            a = f5Var.a();
            L2 = e4.L(a);
        } else {
            e6 e6Var = (e6) value;
            L = e4.L(8) << 1;
            M = e4.M(2, ((p4) entry.getKey()).q()) + L;
            L = e4.L(24);
            a = e6Var.b();
            L2 = e4.L(a);
        }
        return ((L2 + a) + L) + M;
    }

    public final Object c(T t) {
        Object obj = this.a.get(t);
        if (!(obj instanceof f5)) {
            return obj;
        }
        f5 f5Var = (f5) obj;
        int i = f5.c;
        throw new NoSuchMethodError();
    }

    public final /* synthetic */ Object clone() throws CloneNotSupportedException {
        Entry d;
        n4 n4Var = new n4();
        for (int i = 0; i < this.a.e(); i++) {
            d = this.a.d(i);
            n4Var.i((p4) d.getKey(), d.getValue());
        }
        for (Entry d2 : this.a.g()) {
            n4Var.i((p4) d2.getKey(), d2.getValue());
        }
        n4Var.c = this.c;
        return n4Var;
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof n4)) {
            return false;
        }
        return this.a.equals(((n4) obj).a);
    }

    public final void h() {
        if (!this.b) {
            this.a.c();
            this.b = true;
        }
    }

    public final int hashCode() {
        return this.a.hashCode();
    }

    public final void i(T t, Object obj) {
        if (!t.f()) {
            e(t.r(), obj);
        } else if (obj instanceof List) {
            ArrayList arrayList = new ArrayList();
            arrayList.addAll((List) obj);
            int size = arrayList.size();
            int i = 0;
            while (i < size) {
                Object obj2 = arrayList.get(i);
                i++;
                e(t.r(), obj2);
            }
            obj = arrayList;
        } else {
            throw new IllegalArgumentException("Wrong object type used with protocol message reflection.");
        }
        if (obj instanceof f5) {
            this.c = true;
        }
        this.a.put(t, obj);
    }

    public final void j(Entry<T, Object> entry) {
        p4 p4Var = (p4) entry.getKey();
        Object value = entry.getValue();
        Object c;
        if (value instanceof f5) {
            f5 f5Var = (f5) value;
            int i = f5.c;
            throw new NoSuchMethodError();
        } else if (p4Var.f()) {
            c = c(p4Var);
            if (c == null) {
                c = new ArrayList();
            }
            for (Object d : (List) value) {
                ((List) c).add(d(d));
            }
            this.a.put(p4Var, c);
        } else if (p4Var.s() == y7.MESSAGE) {
            c = c(p4Var);
            if (c == null) {
                this.a.put(p4Var, d(value));
                return;
            }
            if (c instanceof h6) {
                value = p4Var.i((h6) c, (h6) value);
            } else {
                value = ((b) p4Var.h(((e6) c).c(), (e6) value)).l();
            }
            this.a.put(p4Var, value);
        } else {
            this.a.put(p4Var, d(value));
        }
    }

    public final Iterator<Entry<T, Object>> l() {
        if (this.c) {
            return new k5(this.a.entrySet().iterator());
        }
        return this.a.entrySet().iterator();
    }

    public final boolean m() {
        for (int i = 0; i < this.a.e(); i++) {
            if (!f(this.a.d(i))) {
                return false;
            }
        }
        for (Entry f : this.a.g()) {
            if (!f(f)) {
                return false;
            }
        }
        return true;
    }

    public n4() {
        int i = t6.g;
    }
}
